package net.mingsoft.report_data.util;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * 数组工具类
 * @author gengfa
 * @date 22/06/14
 */
@Slf4j
public class ArrayUtil {
    private ArrayUtil() {}

    public static List<List<Integer>> getGrowthPart(List<? extends Comparable<? extends Number>> list) {
        List<List<Integer>> growthList = new ArrayList<>();

        if (list.size() == 0 || list.size() == 1) {
            return growthList;
        }

        Comparable tmp = list.get(0);
        int startIndex = 0;
        int endIndex = 0;
        for (int i = 1; i < list.size(); i++) {
            if (tmp.compareTo(list.get(i)) > 0) {
                if (startIndex != endIndex) {
                    growthList.add(Arrays.asList(startIndex, endIndex));
                }
                startIndex = i;
            }
            endIndex = i;
            tmp = list.get(i);
        }
        if (startIndex < list.size() - 1) {
            growthList.add(Arrays.asList(startIndex, list.size() - 1));
        }
        return growthList;
    }
}
